package com.ch05.ex47;

import java.util.Date;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

/**
 * Created by zc on 16-2-21.
 */
public class Client implements Runnable{
    private LinkedBlockingDeque<String> requestList;

    public Client(LinkedBlockingDeque<String> requestList) {
        this.requestList = requestList;
    }

    @Override
    public void run() {
        for(int i=0; i<3; i++){
            for(int j=0; j<5; j++){
                StringBuilder request = new StringBuilder();
                request.append(i).append(":").append(j);
                requestList.push(request.toString());

                System.out.printf("Client: %s at %s.\n",
                        request, new Date());
            }

            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.printf("Client: End.\n");
    }
}
